home *** CD-ROM | disk | FTP | other *** search
/ PC & Mediji 1998 February / PCM_9802.iso / programi / director / data.z / Behavior Library.cst / 00050_Script_UI Drag Snap to Sprite < prev    next >
Text File  |  1997-05-09  |  2KB  |  74 lines

  1. -- Gesture Snap to Sprite
  2.  
  3.  
  4. property  snapDistance, snapTarget, xoffset, yoffset
  5. property tracking, boxtop, boxleft, boxright,boxbottom
  6.  
  7. on beginsprite  me
  8.   set boxtop    = the locv of sprite snapTarget  - snapDistance
  9.   set boxbottom = the locv of sprite snapTarget  + snapDistance
  10.   set boxleft   = the loch of sprite snapTarget  - snapDistance
  11.   set boxright  = the loch of sprite snapTarget  + snapDistance  
  12.   
  13.   
  14. end
  15.  
  16. on prepareframe me
  17.   if tracking then
  18.     if inbox (me, the mouseH - xoffset, the mouseV - yoffset) then 
  19.       snap me
  20.     else
  21.       set the locH of sprite the spritenum of me = the MouseH - xoffset
  22.       set the locV of sprite the spritenum of me = the MouseV - yoffset
  23.     end if
  24.   end if
  25. end
  26.  
  27. on mousedown me
  28.   set tracking  = TRUE
  29.   set xoffset = the mouseH - the locH of sprite the spritenum of me
  30.   set yoffset = the mouseV - the locV of sprite the spritenum of me
  31.   
  32. end
  33.  
  34. on mouseup me
  35.   set tracking = FALSE
  36. end
  37.  
  38. on snap me
  39.   set the locH of sprite the spritenum of me = the locH of sprite snapTarget 
  40.   set the locV of sprite the spritenum of me = the locV of sprite snapTarget  
  41. end
  42.  
  43.  
  44. on inbox me,x,y
  45.   if x < boxright and x > boxleft and y < boxbottom and y > boxtop then
  46.     return 1
  47.   end if
  48.   return 0
  49. end
  50.  
  51.  
  52. ---
  53.  
  54. on getPropertyDescriptionList
  55.   
  56.   set p_list = [ ¼
  57.   #snapDistance: [ #comment: "Snap Distance:", ¼
  58.                     #format: #integer, ¼
  59.                    #default:  8 ], ¼
  60.      #snapTarget: [ #comment: "Target Sprite:", ¼
  61.                     #format: #integer, ¼
  62.                     #default:  1 ] ¼
  63.                  ]
  64.   return p_list 
  65. end
  66.  
  67. on getBehaviorDescription
  68.   return ¼
  69. "Cause a sprite to snap to the registration point of the target sprite while being dragged.  " & RETURN & ¼
  70. "PARAMETERS:" & RETURN & ¼
  71. "ò Snap Distance - Enter the range in pixels within which snapping occurs." & RETURN & ¼
  72. "ò Snap Target - Enter the channel number of the sprite to snap to." 
  73.   
  74. end